package admin

import (
	"html/template"
	"xianzhi/service"
	"xianzhi/utils"
)

type SiteConfigController struct {
	BaseController
}

func (c *SiteConfigController) Edit() {
	id := c.Ctx.Input.Param(":id")

	p := map[string]interface{}{}
	p["id"] = id
	c.Data["record"] = service.GetSiteConfigInfo(p)

	c.Data["xsrfdata"] = template.HTML(c.XSRFFormHTML())
	c.TplName = "admin/site-config/edit.html"
}

func (c *SiteConfigController) DoEdit() {
	var res *utils.ResJsonStruct
	input := c.Input()
	if len(input["selected_tips"][0]) <= 0 {
		res = utils.ResJson(0, "请输入购买后提示", "")
		c.Data["json"] = res
		c.ServeJSON()
		return
	}

	_, err := service.EditSiteConfig(input)
	if err != nil {
		res = utils.ResJson(0, "修改失败", "")
		c.Data["json"] = res
		c.ServeJSON()
		return
	}

	res = utils.ResJson(1, "修改成功", "")
	c.Data["json"] = res
	c.ServeJSON()
}
